<script setup lang="ts">
import {message} from "ant-design-vue";
import DownOutlined from "@ant-design/icons-vue/DownOutlined";
// 关键词抢位设置
import {WxtBizCode} from "~/contentScripts/views/wxt/lib/wxtUtils";
import GrabSeat
  from "~/contentScripts/views/wxt/SuperOptimization/KeywordPromotion/KeywordsOptimizationContent/GrabSeat.vue";
import GrabStop
  from "~/contentScripts/views/wxt/SuperOptimization/KeywordPromotion/KeywordsOptimizationContent/GrabStop.vue";

const props = defineProps({
  rows: {
    type: Array,
    default: () => []
  },
  bizCode: {
    type: String as PropType<WxtBizCode>,
    default: WxtBizCode.关键字推广,
  },
});
const realRows = ref<any[]>(props.rows.filter((row: any) => row.type === 'kw'));
const visible = ref(false);
const emit = defineEmits([
  "refresh",
]);
watch(() => props.rows, (newVal) => {
  realRows.value = newVal.filter((row: any) => row.type === 'kw');
});
const handleMenuClick = (e: any) => {
  if (realRows.value.length === 0) {
    message.error('请选择需要批量处理的数据！');
    return;
  }
  console.log('click', e);
  if (e.key === '1') {
    visible.value = true;
  } else if (e.key === '2') {
    message.info('停止抢位');
  }
  visible.value = true;
}
// [
//   {
//     "bidwordId": 1325957411129,
//     "campaignId": "68795158469",
//     "adgroupId": "69667843938",
//     "bidStrategyInfo": {
//       "bizCode": null,
//       "discount": 1,
//       "rank": 6,
//       "status": 1,
//       "rankName": "前六名"
//     }
//   },
//   {
//     "bidwordId": 1325957411131,
//     "campaignId": "68795158469",
//     "adgroupId": "69667843938",
//     "bidStrategyInfo": {
//       "bizCode": null,
//       "discount": 1,
//       "rank": 6,
//       "status": 1,
//       "rankName": "前六名"
//     }
//   }
// ]
const rank = ref(1);
const discount = ref(0);
const ok = () => {
  console.log('ok');
  if (discount.value < 1 || discount.value > 200) {
    message.error('抢位溢价设置范围为1-200');
    return;
  }
  console.log(realRows.value, rank.value, discount.value);
  visible.value = false;
}
</script>

<template>
  <div style="display: inline-block">
    <a-dropdown>
      <template #overlay>
        <a-menu>
          <a-menu-item>
            <GrabSeat :rows="rows" :biz-code="bizCode" @refresh="emit('refresh')">抢位设置</GrabSeat>
          </a-menu-item>
          <a-menu-item key="2">
            <GrabStop :rows="rows" :biz-code="bizCode" @refresh="emit('refresh')">停止抢位</GrabStop>
          </a-menu-item>
        </a-menu>
      </template>
      <slot>
        <a-button type="primary" size="small" ghost>
          抢位设置
          <DownOutlined/>
        </a-button>
      </slot>
    </a-dropdown>
  </div>
</template>

<style scoped>

</style>
